<template>
	<el-dialog :title="titleMap[mode]" v-model="visible" width="700" destroy-on-close @closed="$emit('closed')" align-center>
        <el-container>
            <el-header>
                <el-button type="success" plain @click="materExport">导出</el-button>
            </el-header>
            <el-main class="nopadding">
                <scTable ref="table" row-key="id" :data="data" border height="500" hidePagination hideDo :cell-style="cellStyle">
                    <el-table-column width="1"></el-table-column>
                    <el-table-column label="物料型号" prop="goods_model" align="center"></el-table-column>
                    <el-table-column label="颜色" prop="color" align="center"></el-table-column>
                    <el-table-column label="方向" prop="direction" align="center"></el-table-column>
                    <el-table-column label="所需数量" prop="number" align="center"></el-table-column>
                    <el-table-column label="库存数量" prop="curr_stock" align="center"></el-table-column>
                    <!-- <el-table-column type="selection" width="50" reserve-selection align="center"></el-table-column> -->
                    <!-- <el-table-column type="index" label="序号" fixed align="center" width="60"></el-table-column>
                    <el-table-column label="产品型号" fixed prop="goods_model" align="center" width="100"></el-table-column>
                    <el-table-column label="速比" prop="speed_ratio.name" align="center" width="100"></el-table-column>
                    <el-table-column label="法兰" prop="flange.name" align="center" width="100"></el-table-column>
                    <el-table-column label="颜色" prop="color.name" align="center" width="100"></el-table-column>
                    <el-table-column label="BOM" align="center">
                        <template #default="scope">
                            <div v-for="(item,index) in scope.row.child" :key="index">
                                <span>
                                    物料型号: {{item.goods_name}}
                                </span>
                                <span style="margin-left: 10px">
                                    数量: {{item.number}}
                                </span>
                            </div>
                        </template>
                    </el-table-column> -->
                </scTable>
            </el-main>
        </el-container>
		<template #footer>
			<el-button @click="visible = false">取 消</el-button>
		</template>
	</el-dialog>
</template>

<script>
export default {
	emits: ['success', 'closed'],
	data() {
		return {
			mode: "add",
			titleMap: {
				add: '报料单',
				edit: '编辑销售',
				show: '查看'
			},
			visible: false,
			isSaveing: false,
			data: [],
            id: "",
		}
	},
	mounted() {
	},
	methods: {
        cellStyle(row){
            let cellStyle = '';
            switch(row.row.is_stock){
                case 1:
                    cellStyle = {color:'#000',backgroundColor:'rgba(255, 63, 13, 0.1)'}
                    break;
                default:
                    cellStyle = {color:'#000',backgroundColor:'#ffffff'}
            }
            return cellStyle
        },
		// 显示
		open(mode = 'add') {
			this.mode = mode;
			this.visible = true;
			return this
		},
        async setData(data){
            var res = await this.$API.production.plan.mater.get({id:data.id});
            this.data = res.data;
            this.id = data.id;
        },
        async materExport(){
            let query = {
                id:this.id,
            }
            var res = await this.$API.production.plan.materExport.get(query)
            if (res.code == 1) {
                const fileUrl = res.data.url;
                const link = document.createElement("a");
                link.href = fileUrl;
                link.download = fileUrl;
                link.click();
            } else {
                this.$alert(res.message, "提示", { type: "error" });
            }
        },
	}
}
</script>

<style></style>
